import cx from 'classnames';
import * as React from 'react';
import Switch from '../../../../Switch';

import type { EditableCell } from './type';

export interface EditableSwitchProps extends EditableCell {
  value: boolean;
}

export default function EditableSwitch(props: EditableSwitchProps) {
  const {
    align,
    columnId,
    value,
    curModalParams,
    onChange,
    onBlur,
    onClick,
    onDoubleClick,
    onMouseEnter,
    onMouseLeave,
    ...restProps
  } = props;
  return (
    <Switch
      {...restProps}
      className={cx(align)}
      checked={!!value}
      onChange={(checked) => {
        onChange(checked);
        onBlur(checked);
      }}
      onClick={
        onClick && onClick.bind(this, { id: columnId, params: curModalParams })
      }
    />
  );
}
